package com.wc.AlgoOJ_train.train2_DP训练.c3.DP0108;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/13 0:09
 * @description 混合背包
 * http://43.138.190.70:8888/p/DP0108
 */
public class Main {
    static int maxN = 1000 + 7;
    static int[] dp = new int[maxN];
    static int[] ws = new int[maxN];
    static int[] vs = new int[maxN];
    static int[] ls = new int[maxN];
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            int a = sc.nextInt();
            ws[i] = sc.nextInt();
            vs[i] = sc.nextInt();
            if (a == 1) {
                ls[i] = 1;
            } else if (a == 2) {
                ls[i] = -1;
            } else {
                ls[i] = sc.nextInt();
            }
        }
        for (int i = 1; i <= n; i++) {
            // 第一类和第三类是一样的
            if (ls[i] > 0) {
                for (int k = 1; ls[i] > 0; k <<= 1) {
                    if (ls[i] < k) k = ls[i];
                    ls[i] -= k;
                    for (int j = m; j >= k * ws[i]; j--) {
                        dp[j] = Math.max(dp[j], dp[j - k * ws[i]] + k * vs[i]);
                    }
                }
            } else {
                for (int j = ws[i]; j <= m; j++) {
                    dp[j] = Math.max(dp[j], dp[j - ws[i]] + vs[i]);
                }
            }
        }
        out.println(dp[m]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
